using MySqlConnector;

namespace Front._1118;

public partial class Login : Form
{
    public Login()
    {
        InitializeComponent();
    }

    private void button1_Click(object sender, EventArgs e)
    {
        //测试数据库连接
        using var connection = new MySqlConnection("server=localhost;port=3306;database=book;user=root;password=Zxcvbnm0000;charset=utf8mb4;AllowPublicKeyRetrieval=True;");
        connection.Open();
        String sql="select * from admin_info where admin_account = @username and admin_password = @pwd";
        string username = this.textBox1.Text;
        string pwd = this.textBox2.Text;
        //对明文密码进行MD5加密
        pwd=MD5Helper.GetMD5(pwd);
        using var command = new MySqlCommand(sql, connection);
        //给sql语句变量填充值
        command.Parameters.AddWithValue("@username", username);
        command.Parameters.AddWithValue("@pwd", pwd);
        using var reader = command.ExecuteReader();
        if (reader.HasRows)
        {
            MainForm mainForm = new MainForm();
            mainForm.Show();
            this.Hide();
        }
        else
        {
            MessageBox.Show("账户或密码错误");
            textBox1.Text = "";
            textBox2.Text = "";
        }

    }

    private void textBox1_TextChanged(object sender, EventArgs e)
    {
        
    }

    private void Login_Load(object sender, EventArgs e)
    {
        this.textBox1.Text = "admin_super01";
        this.textBox2.Text = "123456";
    }
}